package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.model.business.Product;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    //物资资料分页列表展示
    @GetMapping("/findProductList")
    public ResponseBean<PageVO<ProductVO>> findProductList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                           @RequestParam(defaultValue = "6") Integer pageSize,
                                                           String name,
                                                           Long categoryId,
                                                           String supplier,
                                                           Integer status,
                                                           String categorys){
        PageVO<ProductVO> pageVO = productService.findProductList(pageNum,
                pageSize,
                name,
                categoryId,
                supplier,
                status,
                categorys);
        return ResponseBean.success(pageVO);
    }

    //添加物资
    @PostMapping("/add")
    public ResponseBean addProduct(@RequestBody ProductVO productVO){
        productService.addProduct(productVO);
        return ResponseBean.success();
    }

    //编辑物资
    @GetMapping("/edit/{id}")
    public ResponseBean editProduct(@PathVariable Long id){
        Product product = productService.editProduct(id);
        return ResponseBean.success(product);
    }

    //更新物资
    @PutMapping("/update/{id}")
    public ResponseBean updateProduct(@PathVariable Long id,
                                      @RequestBody Product product){
        productService.updateProduct(product);
        return ResponseBean.success();
    }

    //物资移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean removeProduct(@PathVariable Long id){
        productService.removeProduct(id);
        return ResponseBean.success();
    }

    //物资恢复到正常状态
    @PutMapping("/back/{id}")
    public ResponseBean backProduct(@PathVariable Long id){
        productService.backProduct(id);
        return ResponseBean.success();
    }

    //物资删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteProduct(@PathVariable Long id){
        productService.deleteProduct(id);
        return ResponseBean.success();
    }

    //物资审核
    @PutMapping("/publish/{id}")
    public ResponseBean publishProduct(@PathVariable Long id){
        productService.publishProduct(id);
        return ResponseBean.success();
    }

    //查询物资库存
    @GetMapping("/findProductStocks")
    public ResponseBean<PageVO<ProductStockVO>> findProductStocks(@RequestParam(defaultValue = "9") Integer pageSize,
                                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                                  String categorys,
                                                                  String name){

        PageVO<ProductStockVO> pageVO = productService.findProductStocks(pageNum,pageSize,categorys,name);
        return ResponseBean.success(pageVO);
    }

    //查询所有物资库存
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(@RequestParam(defaultValue = "9") Integer pageSize,
                                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                                  String categorys,
                                                                  String name){
        PageVO<ProductStockVO> pageVO = productService.findProductStocks(pageNum,pageSize,categorys,name);
        List<ProductStockVO> productStockVOList = pageVO.getRows();
        return ResponseBean.success(productStockVOList);
    }
}
